﻿//======================================================
//==     (c)2008 aspxcms inc by NeTCMS v1.0              ==
//==          Forum:bbs.aspxcms.com                   ==
//==         Website:www.aspxcms.com                  ==
//======================================================
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using NetCMS.Content;
using NetCMS.Content.Common;

public partial class manage_model_read : NetCMS.Web.UI.ManagePage
{
    Channel rd = new Channel();
    public string SiteList = string.Empty;
    public string IsSuper = string.Empty;

    protected void Page_Load(object sender, EventArgs e)
    {
        #region 读取会员拥有权限的栏目
        NetCMS.Content.AdminGroup agc = new NetCMS.Content.AdminGroup();
        IsSuper = agc.GetAdminIsSuper(this.UserNum);

        if (IsSuper != "1")//判断是不是超级管理员
        {
            string adminGroupNumber = agc.getAdminGroup(this.UserNum);
            IDataReader rdg = agc.getAdminGroups(adminGroupNumber);
            while (rdg.Read())
            {
                if (!rdg.IsDBNull(2))
                {
                    SiteList = rdg.GetString(2);
                }
            }
            rdg.Close();
        }
        #endregion

        if (!IsPostBack)
        {
            Response.CacheControl = "no-cache";
            Response.Expires = 0;
            string ChID = Request.QueryString["ChID"];
            if (ChID != null && ChID != string.Empty)
            {
                channelDivMenu.InnerHtml = GetModelMenu(0, 0);
                ModelContent.InnerHtml = getChannelContent(ChID.ToString());
            }
            else
            {
                PageError("错误的参数", "javascript:history.back()", true);
            }
        }
    }

    protected string GetModelMenu(int ParentID, int Layer)
    {
        string listchmenu = string.Empty;
        IDataReader drs = rd.getModelTemplet(ParentID);
        while (drs.Read())
        {
            string stxt = "";
            if (Layer > 0)
            {
                stxt = "┞┄ ";
            }

            if (IsSuper == "1")
            {
                listchmenu += "<li style=\"list-style:none;\">" + stxt + "<img src='../../sysImages/" + NetCMS.Config.UIConfig.CssPath() + "/admin/menu_dot_21.gif' alt='' border='0'><a class=\"menu_ctr\" href=\"../channel/read.aspx?ChID=" + drs["ID"].ToString() + "\" target=\"menu\">" + drs["channelName"].ToString() + "</a></li>\r";
            }
            else
            {
                if (SiteList.IndexOf(drs["ID"].ToString()) >= 0)
                {
                    listchmenu += "<li style=\"list-style:none;\">" + stxt + "<img src='../../sysImages/" + NetCMS.Config.UIConfig.CssPath() + "/admin/menu_dot_21.gif' alt='' border='0'><a class=\"menu_ctr\" href=\"../channel/read.aspx?ChID=" + drs["ID"].ToString() + "\" target=\"menu\">" + drs["channelName"].ToString() + "</a></li>\r";
                }
            }
            listchmenu += GetModelMenu(int.Parse(drs["ID"].ToString()), (Layer + 1));
        }
        drs.Close();
        return listchmenu;
    }

    protected string getChannelContent(string ChID)
    {
        string listStr = string.Empty;
        string Picstr = "<li style=\"list-style:none;padding-left:1px;\"><img src='../../sysImages/" + NetCMS.Config.UIConfig.CssPath() + "/admin/menu_dot_21.gif' alt='' border='0'>";
        IDataReader dr = rd.getChInfoMenu(int.Parse(ChID));
        
        if (dr.Read())
        {
                string channelItem = dr["channelItem"].ToString();
                string gID = dr["id"].ToString();
                string TempletPath = dr["TempletPath"].ToString();
                string isConstr = dr["isConstr"].ToString();
                string channelName = dr["channelName"].ToString();
                NaveName.InnerHtml = channelName + "导航";
                if (dr["hashCount"].ToString() == "0")
                {
                    listStr += "<div>" + Picstr;
                    if (checkPr("D002"))
                    {
                        listStr += "<a target=\"sys_main\" class=\"list_link\" href=\"Content_add.aspx?ChID=" + gID + "\"  onmouseover=\"javascript:setshorcutmenu('none');\">添加" + channelItem + "</a>";
                    }
                    
                    listStr +="&nbsp;┊&nbsp;<a class=\"list_link\" target=\"sys_main\" href=\"Content.aspx?ChID=" + gID + "\" onmouseover=\"javascript:setshorcutmenu('none');\">管理</a></div>";
                    if (isConstr == "1")
                    {
                        listStr += "<div>" + Picstr + "<a class=\"list_link\" target=\"sys_main\" href=\"Content.aspx?ChID=" + gID + "&isConstr=1\" onmouseover=\"javascript:setshorcutmenu('none');\">会员" + channelItem + "管理</a></div>";
                    }

                    listStr += "<div>" + Picstr;
                    if (checkPr("D004"))
                    {
                        listStr += "<a target=\"sys_main\" class=\"list_link\" href=\"Class_add.aspx?ChID=" + gID + "\" onmouseover=\"javascript:setshorcutmenu('none');\">创建栏目</a>";
                    }
                    if (checkPr("D005"))
                    {
                        listStr += "&nbsp;┊&nbsp;<a class=\"list_link\" target=\"sys_main\" href=\"Class_list.aspx?ChID=" + gID + "\" onmouseover=\"javascript:setshorcutmenu('none');\">管理</a>";
                    }

                    listStr += "</div><div>" + Picstr;
                    if (checkPr("D006"))
                    {
                        listStr += "<a target=\"sys_main\" class=\"list_link\" href=\"Special_add.aspx?ChID=" + gID + "\" onmouseover=\"javascript:setshorcutmenu('none');\">创建专题</a>";
                    }
                    if (checkPr("D007"))
                    {
                        listStr += "&nbsp;┊&nbsp;<a class=\"list_link\" target=\"sys_main\" href=\"Special_list.aspx?ChID=" + gID + "\" onmouseover=\"javascript:setshorcutmenu('none');\">管理</a>";
                    }
                    listStr += "</div><div style=\"margin:0;padding:15px;padding:3px 15px;width:60%;text-align:center;height:3px;border-bottom:1px dotted #C6C6C6;\"></div>";
                }

                listStr += "<div>" + Picstr;
                if (checkPr("T001"))
                {
                    listStr += "<a target=\"sys_main\" class=\"list_link\" onmouseover=\"javascript:setshorcutmenu('none');\" href=\"../Templet/Manage_List.aspx?ChID=" + gID + "&ch=1&Path=\\" + TempletPath.Replace("/", "\\").Replace("\\\\", "\\") + "\">模板管理</a></div>";
                }
                
                if (dr["hashCount"].ToString() == "0")
                {
                    listStr += "<div>" + Picstr;
                    if (checkPr("D008"))
                    {
                        listStr += "<a target=\"sys_main\" class=\"list_link\" onmouseover=\"javascript:setshorcutmenu('none');\" href=\"Label_add.aspx?ChID=" + gID + "\">创建标签</a>";
                    }
                    if (checkPr("D009"))
                    {
                        listStr += "&nbsp;┊&nbsp;<a class=\"list_link\" target=\"sys_main\" href=\"Label_list.aspx?ChID=" + gID + "\" onmouseover=\"javascript:setshorcutmenu('none');\">管理</a>";
                    }

                    listStr += "</div><div>" + Picstr;
                    if (checkPr("D010"))
                    {
                        listStr +="<a target=\"sys_main\" class=\"list_link\" onmouseover=\"javascript:setshorcutmenu('none');\" href=\"style_add.aspx?ChID=" + gID + "\">创建样式</a>";
                    }
                    if (checkPr("D011"))
                    {
                        listStr +="&nbsp;┊&nbsp;<a class=\"list_link\" target=\"sys_main\" href=\"style_list.aspx?ChID=" + gID + "\" onmouseover=\"javascript:setshorcutmenu('none');\">管理</a>";
                    }
                    listStr += "</div>";
                }
                if (checkPr("D012"))
                {
                    listStr += "<div>" + Picstr+"<a target=\"sys_main\" class=\"list_link\" onmouseover=\"javascript:setshorcutmenu('none');\" href=\"publish.aspx?ChID=" + gID + "\">发布频道</a></div>";
                }
               
                if (dr["hashCount"].ToString() == "0")
                {
                    listStr += "<div style=\"margin:0;padding:15px;padding:3px 15px;width:60%;text-align:center;height:3px;border-bottom:1px dotted #C6C6C6;\"></div>";
                    listStr += "<div>" + Picstr;
                    if (checkPr("D013"))
                    {
                        listStr +="<a target=\"sys_main\" class=\"list_link\" onmouseover=\"javascript:setshorcutmenu('none');\" href=\"value_add.aspx?ChID=" + gID + "\">添加字段</a>";
                    }
                    if (checkPr("D014"))
                    {
                        listStr += "&nbsp;┊&nbsp;<a class=\"list_link\" target=\"sys_main\" href=\"value.aspx?ChID=" + gID + "\" onmouseover=\"javascript:setshorcutmenu('none');\">管理</a></div>";
                    }
                    listStr += "</div>";
                }
                if (checkPr("C035"))
                {
                    listStr += "<div>" + Picstr + "<a target=\"sys_main\" class=\"list_link\" onmouseover=\"javascript:setshorcutmenu('none');\" href=\"channel_add.aspx?ChID=" + gID + "\">参数设置</a></div>";
                }
        }
        dr.Close();
        return listStr;
    }

    /// <summary>
    /// 权限判断
    /// </summary>
    /// <param name="code">权限代码</param>
    /// <returns></returns>
    public bool checkPr(string code)
    {
        this.Authority_Code = code;
        return CheckAuthority();
    }
}
